package com.ruoyi.web.controller.gcgl;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gcgl.domain.GcCustomer;
import com.ruoyi.gcgl.domain.SjRkinfor;
import com.ruoyi.gcgl.service.IGcCustomerService;
import com.ruoyi.gcgl.service.IGcProjectService;
import com.ruoyi.gcgl.service.ISjRkinforService;

/**
 * 入库信息登记Controller
 * 
 * @author ruoyi
 * @date 2025-08-06
 */
@Controller
@RequestMapping("/sj/rkinfor")
public class SjRkinforController extends BaseController
{
    private String prefix = "sj/rkinfor";

    @Autowired
    private ISjRkinforService sjRkinforService;
    @Autowired
    private IGcCustomerService gcCustomerService;
    @Autowired
    private IGcProjectService gcProjectService;

    @RequiresPermissions("system:rkinfor:view")
    @GetMapping()
    public String rkinfor()
    {
        return prefix + "/rkinfor";
    }

    /**
     * 查询入库信息登记列表
     */
    @RequiresPermissions("system:rkinfor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SjRkinfor sjRkinfor)
    {
        startPage();
        sjRkinfor.setDeleteFlag(1);
        List<SjRkinfor> list = sjRkinforService.selectSjRkinforList(sjRkinfor);
        return getDataTable(list);
    }

    /**
     * 导出入库信息登记列表
     */
    @RequiresPermissions("system:rkinfor:export")
    @Log(title = "入库信息登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SjRkinfor sjRkinfor)
    {
        List<SjRkinfor> list = sjRkinforService.selectSjRkinforList(sjRkinfor);
        ExcelUtil<SjRkinfor> util = new ExcelUtil<SjRkinfor>(SjRkinfor.class);
        return util.exportExcel(list, "入库信息登记数据");
    }

    /**
     * 新增入库信息登记
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
    	GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
        return prefix + "/add";
    }

    /**
     * 新增保存入库信息登记
     */
    @RequiresPermissions("system:rkinfor:add")
    @Log(title = "入库信息登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SjRkinfor sjRkinfor)
    {
    	sjRkinfor.setDeleteFlag(1);
    	sjRkinfor.setCreateAt(new Date());
    	sjRkinfor.setCreateUser(getLoginName());
    	sjRkinfor.setUpdateAt(new Date());
    	sjRkinfor.setUpdateUser(getLoginName());
        return toAjax(sjRkinforService.insertSjRkinfor(sjRkinfor));
    }

    /**
     * 修改入库信息登记
     */
    @RequiresPermissions("system:rkinfor:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SjRkinfor sjRkinfor = sjRkinforService.selectSjRkinforById(id);
        mmap.put("sjRkinfor", sjRkinfor);
        
        GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存入库信息登记
     */
    @RequiresPermissions("system:rkinfor:edit")
    @Log(title = "入库信息登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SjRkinfor sjRkinfor)
    {
    	sjRkinfor.setUpdateAt(new Date());
    	sjRkinfor.setUpdateUser(getLoginName());
        return toAjax(sjRkinforService.updateSjRkinfor(sjRkinfor));
    }

    /**
     * 删除入库信息登记
     */
    @RequiresPermissions("system:rkinfor:remove")
    @Log(title = "入库信息登记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sjRkinforService.deleteSjRkinforByIds(ids));
    }
}
